import { IPSModelSortable } from '../ipsmodel-sortable';
import { IPSCodeList } from '../codelist/ipscode-list';
import { IPSDataEntity } from '../dataentity/ipsdata-entity';
import { IPSSysSFPlugin } from '../res/ipssys-sfplugin';
import { IPSSysModelGroup } from './ipssys-model-group';
import { IPSSysRef } from './ipssys-ref';
import { IPSSystemModule } from './ipssystem-module';
import { IPSWorkflow } from '../wf/ipsworkflow';
import { PSModelObjectImpl } from '../psmodel-object-impl';

export class PSSystemModuleImpl extends PSModelObjectImpl implements IPSSystemModule, IPSModelSortable {
  protected allpscodelists: IPSCodeList[] | null = null;

  getAllPSCodeLists(): IPSCodeList[] | null {
    if (this.allpscodelists == null) {
      this.allpscodelists = this.fillChildListModel(this.M.getAllPSCodeLists, 'codelist.IPSCodeList') as IPSCodeList[];
    }
    return this.allpscodelists;
  }

  get allPSCodeLists(): IPSCodeList[] | null {
    return this.getAllPSCodeLists();
  }

  findPSCodeList(objKey: any): IPSCodeList | null {
    return this.getPSModel5('codelist.IPSCodeList', this.getAllPSCodeLists(), objKey) as IPSCodeList;
  }

  protected allpsdataentities: IPSDataEntity[] | null = null;

  getAllPSDataEntities(): IPSDataEntity[] | null {
    if (this.allpsdataentities == null) {
      this.allpsdataentities = this.fillChildListModel(this.M.getAllPSDataEntities, 'dataentity.IPSDataEntity') as IPSDataEntity[];
    }
    return this.allpsdataentities;
  }

  get allPSDataEntities(): IPSDataEntity[] | null {
    return this.getAllPSDataEntities();
  }

  findPSDataEntity(objKey: any): IPSDataEntity | null {
    return this.getPSModel5('dataentity.IPSDataEntity', this.getAllPSDataEntities(), objKey) as IPSDataEntity;
  }

  protected allpsworkflows: IPSWorkflow[] | null = null;

  getAllPSWorkflows(): IPSWorkflow[] | null {
    if (this.allpsworkflows == null) {
      this.allpsworkflows = this.fillChildListModel(this.M.getAllPSWorkflows, 'wf.IPSWorkflow') as IPSWorkflow[];
    }
    return this.allpsworkflows;
  }

  get allPSWorkflows(): IPSWorkflow[] | null {
    return this.getAllPSWorkflows();
  }

  findPSWorkflow(objKey: any): IPSWorkflow | null {
    return this.getPSModel5('wf.IPSWorkflow', this.getAllPSWorkflows(), objKey) as IPSWorkflow;
  }

  get codeName(): string {
    return this.M.codeName;
  }

  get dSLink(): 'DEFAULT' | 'DB2' | 'DB3' | 'DB4' | 'DB5' | 'DB6' | 'DB7' | 'DB8' | 'DB9' | 'DB10' | 'DB11' | 'DB12' {
    return this.M.dSLink;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get memo(): string {
    return this.M.memo;
  }

  get moduleSN(): string {
    return this.M.moduleSN;
  }

  get moduleTag(): string {
    return this.M.moduleTag;
  }

  get moduleTag2(): string {
    return this.M.moduleTag2;
  }

  get moduleTag3(): string {
    return this.M.moduleTag3;
  }

  get moduleTag4(): string {
    return this.M.moduleTag4;
  }

  get name(): string {
    return this.M.name;
  }

  get orderValue(): number {
    return this.M.orderValue != null ? this.M.orderValue : 99999;
  }

  get pKGCodeName(): string {
    return this.M.pKGCodeName;
  }

  protected pssysmodelgroup: IPSSysModelGroup | null = null;

  getPSSysModelGroup(): IPSSysModelGroup | null {
    if (this.pssysmodelgroup != null) return this.pssysmodelgroup;
    const value = this.M.getPSSysModelGroup;
    if (value == null) {
      return null;
    }
    this.pssysmodelgroup = this.getPSModel4('system.IPSSysModelGroup', value, 'getPSSysModelGroup') as IPSSysModelGroup;
    return this.pssysmodelgroup;
  }

  get psSysModelGroup(): IPSSysModelGroup | null {
    return this.getPSSysModelGroup();
  }

  getPSSysModelGroupMust(): IPSSysModelGroup {
    const value = this.getPSSysModelGroup();
    if (value == null) {
      throw new Error('未指定系统模型组');
    }
    return value;
  }

  protected pssysref: IPSSysRef | null = null;

  getPSSysRef(): IPSSysRef | null {
    if (this.pssysref != null) return this.pssysref;
    const value = this.M.getPSSysRef;
    if (value == null) {
      return null;
    }
    this.pssysref = this.getPSModel4('system.IPSSysRef', value, 'getPSSysRef') as IPSSysRef;
    return this.pssysref;
  }

  get psSysRef(): IPSSysRef | null {
    return this.getPSSysRef();
  }

  getPSSysRefMust(): IPSSysRef {
    const value = this.getPSSysRef();
    if (value == null) {
      throw new Error('未指定系统引用');
    }
    return value;
  }

  protected pssyssfplugin: IPSSysSFPlugin | null = null;

  getPSSysSFPlugin(): IPSSysSFPlugin | null {
    if (this.pssyssfplugin != null) return this.pssyssfplugin;
    const value = this.M.getPSSysSFPlugin;
    if (value == null) {
      return null;
    }
    this.pssyssfplugin = this.getPSModel4('res.IPSSysSFPlugin', value, 'getPSSysSFPlugin') as IPSSysSFPlugin;
    return this.pssyssfplugin;
  }

  get psSysSFPlugin(): IPSSysSFPlugin | null {
    return this.getPSSysSFPlugin();
  }

  getPSSysSFPluginMust(): IPSSysSFPlugin {
    const value = this.getPSSysSFPlugin();
    if (value == null) {
      throw new Error('未指定后台扩展插件');
    }
    return value;
  }

  get sysRefType(): 'SUBSYS' | 'DEVSYS' | 'DEVSYSCLOUD' | 'CLOUDHUBSUBAPP' | 'ETLEXTRACT' | 'ETLTRANSFORM' | 'ETLLOAD' | 'ETLSOURCE' | 'ETLMODEL' | 'USER' | 'USER2' | 'USER3' | 'USER4' {
    return this.M.sysRefType;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get utilParams(): IModel {
    return this.M.utilParams;
  }

  get utilTag(): string {
    return this.M.utilTag;
  }

  get utilType(): 'ADMIN' | 'EAI' | 'BI' | 'USER' | 'USER2' | 'USER3' | 'USER4' {
    return this.M.utilType;
  }

  get defaultModule(): boolean {
    return this.M.defaultModule != null ? this.M.defaultModule : false;
  }

  get subSysAsCloud(): boolean {
    return this.M.subSysAsCloud != null ? this.M.subSysAsCloud : false;
  }

  get subSysModule(): boolean {
    return this.M.subSysModule != null ? this.M.subSysModule : false;
  }

  get cls(): string {
    return 'PSSystemModuleImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'IPSModelSortable' || cls == 'system.IPSSystemModule') return true;
    return super.instanceof(cls);
  }
}
